import request from '@/utils/request'

// 获取所有油料设施
export function getAllFacilities(region = 'all') {
  return request({
    url: '/api/oil-supply/facilities',
    method: 'get',
    params: { region }
  }).catch(error => {
    console.error('获取所有油料设施失败:', error);
    throw error;
  })
}

// 获取单个油料设施详情
export function getFacilityById(id) {
  return request({
    url: `/api/oil-supply/facilities/${id}`,
    method: 'get'
  }).catch(error => {
    console.error(`获取油料设施(ID:${id})详情失败:`, error);
    throw error;
  })
}

// 获取所有供应关系
export function getAllRelations(region = 'all') {
  return request({
    url: '/api/oil-supply/relations',
    method: 'get',
    params: { region }
  }).catch(error => {
    console.error('获取所有供应关系失败:', error);
    throw error;
  })
}

// 获取网络数据
export function getNetworkData(params) {
  return request({
    url: '/api/oil-supply/network',
    method: 'get',
    params
  })
}

// 追踪供应链
export function traceSupplyChain(facilityId) {
  return request({
    url: `/api/oil-supply/trace/${facilityId}`,
    method: 'get'
  })
}

// 初始化测试数据
export function initTestData() {
  return request({
    url: '/api/oil-supply/init-db',
    method: 'post'
  })
}

// 获取初始数据
export function getInitialData() {
  return request({
    url: '/api/oil-supply/network',
    method: 'get',
    params: { region: 'all' }
  })
} 